'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  // app.beforeStart(async () => {
  //   await app.model.sync({ force: true });
  // });
  const { router, controller } = app;

  const { userValidator, verifyUser, verifyLogin, cryptPassword } =
    app.middleware.user;

  const { auth } = app.middleware.auth;

  router.get('/', controller.home.index);

  router.post('/ming', controller.ming.index);

  router.get('/ming/geta', controller.ming.getA);
  router.get('/ming/getb/:name/:age', controller.ming.getB);

  router.post('/ming/girl', controller.ming.addGirl);
  router.delete('/ming/girl/:id', controller.ming.deleteGirl);
  router.patch('/ming/girl', controller.ming.updateGirl);
  router.get('/ming/girl', controller.ming.getGirl);

  router.post('/slize', cryptPassword, controller.slize.addSlize);
  router.delete('/slize/:id', controller.slize.deleteSlize);
  router.patch('/slize', controller.slize.updateSlize);
  router.get('/slize', controller.slize.getSlize);
  router.get('/slizelist', controller.slize.getSlizeList);

  router.post('/upload_file_single', controller.uploadSingleFile.upload);

  router.post(
    '/register',
    userValidator,
    verifyUser,
    cryptPassword,
    controller.user.register
  );
  router.post('/login', userValidator, verifyLogin, controller.user.login);
  router.patch('/setPwd', auth, cryptPassword, controller.user.changePassword);
};
